<%@page import="com.keta.foundation.entity.Organization"%>
<%@page import="org.aspectj.weaver.patterns.OrAnnotationTypePattern"%>
<%@page import="java.util.List"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
	trimDirectiveWhitespaces="true" pageEncoding="UTF-8"%>
<%@ include file="/WEB-INF/views/include.inc.jsp"%>

<%!
public String getTreeJson(String basePath,List<Organization> listOrg) {

	// 这里返回的json有点特殊，手动拼接,不使用jackson注解
	StringBuilder builder = new StringBuilder();
	builder.append("[");
	for (Organization org : listOrg) {

		long pid = org.getParent() == null ? 0 : org.getParent().getId();
		builder.append("{id:" + org.getId() + ", pId:" + pid + ", name:\""
				+ org.getName() + "\", url:\"" + basePath + "/"
				+ org.getId() + "\", target:\"ajax\"},");
	}
	builder.append("]");

	return builder.toString();
}
%>
<%
	List<Organization> orgList = (List<Organization>)request.getAttribute("orgList");
	String tree = getTreeJson(request.getContextPath()+"/organization/list",orgList);
%>


<script type="text/javascript">
var setting = {
	view: {
		//showIcon: false
	},
	data: {
		simpleData: {
			enable:true,
			idKey: "id",
			pIdKey: "pId",
			rootPId: ""
		}
	},
	callback: {
		onClick: function(event, treeId, treeNode) {
			var $rel = $("#ajaxBox2orgList");
			$rel.loadUrl(treeNode.url, {}, function(){
				$rel.find("[layoutH]").layoutH();
			});

			event.preventDefault();
		}
	}	
};
var zNodes =<%=tree%>;
$(document).ready(function(){
	var t = $("#orgTree");
	t = $.fn.zTree.init(t, setting, zNodes);
	t.expandAll(true); 
});
</script>
<ul id="orgTree" class="ztree"></ul>

